<template>
  <div>
    <div class="app-container">
      <!-- 只有商家有积分明细 -->
      <el-row :gutter="10">
        <el-col :span="8">
          <div class="cont-item">
            <div class="cont-item-title">商家总积分</div>
            <div class="count">{{ walletInfo.pointsAll || 0 }}</div>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="cont-item">
            <div class="cont-item-title">已使用积分</div>
            <div class="count">{{ walletInfo.pointsUsed || 0 }}</div>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="cont-item">
            <div class="cont-item-title">剩余积分</div>
            <div class="count">{{ walletInfo.pointsResidual || 0 }}</div>
          </div>
        </el-col>
      </el-row>
      <div class="table-box">
        <div class="cont-item-title">积分明细</div>
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="80px" >
          <el-form-item label="交易时间" prop="dateRange">
            <el-date-picker
              style="max-width: 240px"
              v-model="dateRange"
              type="daterange"
              size="small"
              align="right"
              unlink-panels
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="收支类型" prop="incomeFlag">
            <el-select style="width: 180px" v-model="queryParams.incomeFlag" placeholder="请选择收支类型" clearable>
              <el-option v-for="dict in incomeFlagList" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="订单ID" prop="objectId">
            <el-input v-model="queryParams.objectId" placeholder="请输入订单ID" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="walletList">
          <el-table-column label="交易类型" align="center" prop="produtName" width="150" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.store_biz_code" :value="scope.row.bizCode" />
            </template>
          </el-table-column>
          <el-table-column label="交易时间" align="center" prop="createTime" width="100" />
          <el-table-column label="收支类型" align="center">
            <template slot-scope="scope">
              <div v-if="scope.row.incomeFlag">收入</div>
              <div v-else>支出</div>
            </template>
          </el-table-column>
          <el-table-column label="积分" align="center" prop="amount" />
          <el-table-column label="备注" align="center" prop="remark" />
          <el-table-column label="订单ID" align="center" prop="objectId" />
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      </div>
    </div>
  </div>
</template>
<script>
import { storePointsInfo, walletWalletFlow } from "@/api/asset/asset";
export default {
  name: "integral",
  dicts: ["store_biz_code"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 表格数据
      walletList: [],
      // 日期范围
      dateRange: [],
      incomeFlagList: [
        {
          label: "收入",
          value: 1,
        },
        {
          label: "支出",
          value: 2,
        },
      ],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        walletId: 1,
        incomeFlag: "",
        objectId: "",
      },
      walletInfo: {},
    };
  },
  mounted() {
    this.getList();
    this.getStoreWallet();
  },
  methods: {
    /** 查询钱包信息 */
    getStoreWallet() {
      this.loading = true;
      storePointsInfo().then((response) => {
        this.walletInfo = response.data;
      });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      if (!Array.isArray(this.dateRange)) {
        this.dateRange = [];
      }
      let queryParams = JSON.parse(JSON.stringify(this.queryParams));
      //incomeFlag true 收入  false支出
      queryParams.incomeFlag = queryParams.incomeFlag != "" ? queryParams.incomeFlag === 2 ? false : true : "";
      queryParams.beginCreateTime = this.dateRange[0];
      queryParams.endCreateTime = this.dateRange[1];
      walletWalletFlow(queryParams).then((response) => {
        this.walletList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.form = {
        pageNo: 1,
        pageSize: 10,
        walletId: 1,
      };
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>

<style lang="scss" scoped>
.app-title {
  background: #fff;
  height: 100%;
  min-height: calc(100vh - 84px);
  padding: 16px 20px;
  box-sizing: border-box;
}
.app-container {
  background: #f5f6f9;
  height: 100%;
  min-height: calc(100vh - 84px);
  padding: 16px 20px;
  box-sizing: border-box;
  .cont-item {
    border-radius: 4px;
    background: #fff;
    padding: 30px 20px 20px 36px;
    height: 120px;
    .cont-item-title {
      margin-left: -10px;
    }
    .title-s {
      color: #666;
    }
    .count {
      margin-top: 6px;
      font-weight: 500;
      font-size: 30px;
    }
    .flex {
      display: flex;
      > div {
        width: 50%;
      }
    }
  }
  .cont-item-title {
    font-size: 16px;
    margin-bottom: 10px;
    padding-left: 14px;
    line-height: 16px;
    border-left: 4px solid #105cfb;
  }
  .table-box {
    background: #fff;
    margin-top: 20px;
    padding: 20px;
  }
}
</style>
